package easy.trace.core.context;

import easy.trace.core.util.RpcIdGenerator;

/**
 * @author easy
 */
public class RpcIdContext {

    private final RpcIdGenerator rpcIdGen;
    private ThreadLocal<String> rpcIdThreadLocal = new ThreadLocal<>();

    public void removeLocalRpcId() {
        rpcIdThreadLocal.remove();
    }

    public String getLocalRpcId() {
        return rpcIdThreadLocal.get();
    }

    public void setLocalRpcId(String rpcId) {
        rpcIdThreadLocal.set(rpcId);
    }

    public RpcIdContext() {
        this.rpcIdGen = RpcIdGenerator.get();
    }

    public String genRpcId(String rpcId, String serviceId, String methodName) {
        return rpcIdGen.append(rpcId, serviceId, methodName);
    }

    public String genRpcId(String serviceId, String methodName) {
        return rpcIdGen.append(serviceId, methodName);
    }

}
